<template>
	<view class="body">
		
			<u-navbar :is-back="true" :title="title" title-color="black" :background="background"></u-navbar>
			<view class="face-wapper">
				<image src="../../static/login_logo.png" class="face" mode="aspectFit"></image>
			</view>
			
			<!-- <view class="info-wapper">
				<label class="words-lbl">账号</label>
				<input name="username" type="text" value="" class="input" placeholder="请输入用户名" placeholder-class="graywords"/>
			</view>
			
			<view class="info-wapper" style="margin-top: 40upx;">
				<label class="words-lbl">密码</label>
				<input name="password" type="text" value="" password="true" class="input" placeholder="请输入密码" placeholder-class="graywords"/>
			</view>
			
			<button type="primary" form-type="submit" style="margin-top: 60upx;width: 90%;">注册/登录</button> -->
			<!-- #ifndef H5 -->
			<view class="third-wapper">							
				<view class="third-line">
					<view class="single-line">
						<view class="line"></view>
					</view>
					
					<view class="third-words">微信账号登录</view>
					
					<view class="single-line">
						<view class="line"></view>
					</view>
				</view>
				
				<view class="third-icos-wapper">
					<!-- 5+app 用qq/微信/微博 登录 小程序用微信小程序登录 h5不支持 -->
					<!-- #ifdef APP-PLUS -->
						<image src="../../static/icos/weixin.png" data-logintype="weixin" @click="appOAuthLogin" class="third-ico"></image>
						<image src="../../static/icos/QQ.png" data-logintype="qq" @click="appOAuthLogin" class="third-ico" style="margin-left: 80upx;"></image>
						<image src="../../static/icos/weibo.png" data-logintype="sinaweibo" @click="appOAuthLogin" class="third-ico" style="margin-left: 80upx;"></image>
					<!-- #endif -->
					<!-- #ifdef MP-WEIXIN -->
						<button open-type='getUserInfo' @getuserinfo="wxLogin" class="third-btn-ico">
						</button>
					<!-- #endif -->
				</view>
			</view>
			<!-- #endif -->
			
			<!-- <button type="primary" open-type="getUserInfo" lang="zh_CN"
				@getuserinfo="wxLogin" form-type="submit" style="margin-top: 60upx;width: 90%;">
			<image class="btnImg" src="../../static/wx.png"></image>
				微信一键登录</button> -->
		
	</view>
</template>


<script>
	export default {
		data() {
			return {
				title:"登陆",
				
				background:{
		
					backgroundImage:'linear-gradient(120deg, #fdfbfb 0%, #ebedee 100%)',
					/* background-image: linear-gradient(to top, ffd655#fddb92 0%, #d1fdff 100%); */
				},
			};
		},
		onLoad() {
			
		},
		methods: {
			wxLogin(e) {
				var me = this;
				// 通过微信开发能力，获得微信用户的基本信息
				var userInfo = e.detail.userInfo;
				var baseUrl = me.baseUrl;
				console.log(userInfo)
				// 实现微信登录
				uni.login({
					provider: "weixin",
					success(loginResult) {
						// console.log(loginResult);
						// 获得微信登录的code：授权码
						var code = loginResult.code;
						console.log(code)
						uni.request({
							url: baseUrl + '/mini_program/user-wechat/login?code=' + code,
							data: {
								"nickName": userInfo.nickName,
								"avatarUrl": userInfo.avatarUrl
							},
							dataType: 'json',
							method:'POST',
							success: (res) => {									
								if(res.statusCode == 200){
									var userSkey = res.data.data.skey;
									me.userSkey = userSkey
									me._getUserInfo();
								}
							}							
						})
						uni.hideLoading();
					}
				});
			},
			_getUserInfo(){
				var me=this;
				uni.request({
				    url: 'http://1.117.57.89:8011/mini_program/user-wechat/getUserInfo/'+ me.userSkey,
				    dataType: 'json', // 返回数据格式
				    method:'GET',
				    success: (userResult) => {
						console.log(userResult)
				        console.log(userResult.data.data)
						var userInfo = userResult.data.data;
						uni.setStorageSync("globalUser",userInfo)
						uni.switchTab({
							url:"../mine/mine"
						});
				    }
				})
			}
					
		}
	}
</script>

<style>
	@import url("registLogin_css.css");
</style>
